package com.gk.http.service.impl;

import com.alibaba.fastjson.JSON;
import com.gk.bean.*;
import com.gk.bean.qfdto.T320QueryInfoDto;
import com.gk.bean.qfdto.T340QueryInfoDto;
import com.gk.bean.qfdto.T400QueryInfoDto;
import com.gk.bean.qfdto.T500QueryInfoDto;
import com.gk.http.HttpApi;
import com.gk.http.entity.HttpCommon;
import com.gk.http.entity.HttpRequestParams;
import com.gk.http.entity.HttpResult;
import com.gk.http.service.GetGkDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class GetGkDataServiceImpl implements GetGkDataService {


    @Override
    public HttpResult getGkInStockData(String billCode) {
        T320QueryInfoDto t320QueryInfoDto = new T320QueryInfoDto();
        t320QueryInfoDto.setTrackNbr(billCode);
        HttpRequestParams httpRequestParams = new HttpRequestParams();
        CommonDto commonDto = new CommonDto();
        T320HeaderBean t320HeaderBean = new T320HeaderBean();
        commonDto.getXml().setHeader(t320HeaderBean);
        commonDto.getXml().getContent().getDetail().setMain(t320QueryInfoDto);
        httpRequestParams.getData().add(commonDto);
        log.info("获取国控入库数据:" + JSON.toJSONString(httpRequestParams));
        HttpResult httpResult = new HttpResult();
        try {
            httpResult = HttpApi.getDataHttpApi(httpRequestParams, HttpCommon.GETINSTOCKBILL_URL);
        } catch (Exception e) {
            httpResult.setCode("-99999");
            httpResult.setMsg(e.getMessage());
            httpResult.setData(e.getMessage());
        }
        return httpResult;
    }

    @Override
    public HttpResult getGkOutStockData(String billCode) {
        HttpRequestParams httpRequestParams = new HttpRequestParams();
        T340QueryInfoDto t340QueryInfoDto = new T340QueryInfoDto();
        t340QueryInfoDto.setTrackNbr(billCode);
        CommonDto commonDto = new CommonDto();
        T340HeaderBean t340HeaderBean = new T340HeaderBean();
        commonDto.getXml().setHeader(t340HeaderBean);
        commonDto.getXml().getContent().getDetail().setMain(t340QueryInfoDto);
        httpRequestParams.getData().add(commonDto);
        log.info("获取国控出库数据:" + JSON.toJSONString(httpRequestParams));
        HttpResult httpResult = new HttpResult();
        try {
            httpResult = HttpApi.getDataHttpApi(httpRequestParams, HttpCommon.GETOUTSTOCKBILL_URL);
        } catch (Exception e) {
            httpResult.setCode("-99999");
            httpResult.setMsg(e.getMessage());
            httpResult.setData(e.getMessage());
        }
        return httpResult;
    }

    @Override
    public HttpResult getGkStockAdjustData() {
        HttpRequestParams httpRequestParams = new HttpRequestParams();
        T400QueryInfoDto t400QueryInfoDto = new T400QueryInfoDto();
        CommonDto commonDto = new CommonDto();
        T400HeaderBean t400HeaderBean = new T400HeaderBean();
        commonDto.getXml().setHeader(t400HeaderBean);
        commonDto.getXml().getContent().getDetail().setMain(t400QueryInfoDto);
        httpRequestParams.getData().add(commonDto);
        log.info("获取国控库存调整数据:" + JSON.toJSONString(httpRequestParams));
        HttpResult httpResult = new HttpResult();
        try {
            httpResult = HttpApi.getDataHttpApi(httpRequestParams, HttpCommon.GOODSMOVEMENT_URL);
        } catch (Exception e) {
            httpResult.setCode("-99999");
            httpResult.setMsg(e.getMessage());
            httpResult.setData(e.getMessage());
        }
        return httpResult;
    }

    @Override
    public HttpResult getGkGoodsStocksData() {
        HttpRequestParams httpRequestParams = new HttpRequestParams();
        T500QueryInfoDto t400QueryInfoDto = new T500QueryInfoDto();
        CommonDto commonDto = new CommonDto();
        T500HeaderBean t500HeaderBean = new T500HeaderBean();
        commonDto.getXml().setHeader(t500HeaderBean);
        commonDto.getXml().getContent().getDetail().setMain(t400QueryInfoDto);
        httpRequestParams.getData().add(commonDto);
        log.info("获取国控库存余额数据:" + JSON.toJSONString(httpRequestParams));
        HttpResult httpResult = new HttpResult();
        try {
            httpResult = HttpApi.getDataHttpApi(httpRequestParams, HttpCommon.GOODSSTOCK_URL);
        } catch (Exception e) {
            httpResult.setCode("-99999");
            httpResult.setMsg(e.getMessage());
            httpResult.setData(e.getMessage());
        }
        return httpResult;
    }
}
